﻿@using Microsoft.AspNetCore.Localization
@using IdentityServer4.Extensions
@using Chino.IdentityServer.Const
@inject Microsoft.Extensions.Configuration.IConfiguration configuration
@inject CommonLocalizationService CL
@inject Chino.IdentityServer.Services.Localization.IJsonLocalizationService JL
@inject Chino.IdentityServer.Services.Users.IUserAvatarService UserAvatarService

@{
    ViewData["_layout"] = "user";
    string pageName = (string)(ViewData["pageName"] ?? "unknow");
    var currentCulture = Context.Features.Get<IRequestCultureFeature>()?.RequestCulture?.UICulture;

    string DisplayName = User.GetDisplayName();

    bool IsPage(string name) => pageName == name;

    var userAvatarUrl = await UserAvatarService.GetCurrentUserAvatarUrl(this.User, this.Context.Request, 150);
}

<!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>@(ViewData["Title"] ?? "Chino") - @JL[configuration["Chino:PageTitle"], currentCulture]</title>

    <link rel="stylesheet" href="~/css/chino-user.css" />
    <link rel="stylesheet" href="~/css/chino.css" />

    <environment include="Development">
        <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
    </environment>
    <environment exclude="Development">
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-alpha3/dist/css/bootstrap.min.css"
              asp-fallback-href="~/lib/bootstrap/dist/css/bootstrap.min.css"
              asp-fallback-test-class="col-auto" asp-fallback-test-property="width"
              asp-fallback-test-value="auto"
              integrity="sha384-CuOF+2SnTUfTwSZjCXf01h7uYhfOBuxIhGKPbfEJ3+FqH/s6cIFN9bGr1HmAg4fQ"
              crossorigin="anonymous" />
    </environment>

</head>
<body>
    <header>
        <partial name="Nav" />
    </header>
    <div class="container pb-5 mb-5 pb-md-0 mb-md-0">
        <div class="main-body">

            <div class="row gutters-sm">
                @*左侧边栏*@
                <div class="col-md-4 mb-3">
                    @*头像卡*@
                    <div class="card">
                        <div class="card-body">
                            <div class="d-flex flex-column align-items-center text-center">
                                @*<img src="~/img/default_avatar.png" alt="avatar" class="rounded-circle" width="150">*@
                                <img src="@userAvatarUrl" alt="avatar" class="rounded-circle" width="150">
                                <div class="mt-3">
                                    <h4>@(DisplayName ?? "Unknow Name")</h4>
                                    <p class="text-secondary mb-1">Desc</p>
                                </div>
                            </div>
                        </div>
                    </div>

                    @*链接*@
                    <div class="card mt-3">
                        <div class="list-group">
                            <a asp-page="/User/Index" class="list-group-item list-group-item-action @(IsPage(UserPagesNavConst.UserInfo)?"active":string.Empty)" aria-current="@(IsPage(UserPagesNavConst.UserInfo)?"true":"false")">@CL["user_nav_infos"]</a>
                            <a asp-page="/User/ChangePassword" class="list-group-item list-group-item-action @(IsPage("changePassword")?"active":string.Empty)" aria-current="@(IsPage("changePassword")?"true":"false")">@CL["user_nav_passwd"]</a>
                            <a asp-page="/User/ExternalLogins" class="list-group-item list-group-item-action @(IsPage("externalLogin")?"active":string.Empty)" aria-current="@(IsPage("externalLogin")?"true":"false")">@CL["user_nav_externalLogin"]</a>
                            <a asp-page="/User/Grants" class="list-group-item list-group-item-action @(IsPage("grants")?"active":string.Empty)" aria-current="@(IsPage("grants")?"true":"false")">@CL["user_nav_grants"]</a>
                            <a asp-page="/User/TwoFactorAuthentication" class="list-group-item list-group-item-action @(IsPage("twoFactorAuthentication")?"active":string.Empty)" aria-current="@(IsPage("twoFactorAuthentication")?"true":"false")">@CL["user_nav_twoFactorAuthentication"]</a>
                            <a asp-page="/User/PersonalData" class="list-group-item list-group-item-action @(IsPage(UserPagesNavConst.PersonalData)?"active":string.Empty)" aria-current="@(IsPage(UserPagesNavConst.PersonalData)?"true":"false")">@CL["user_nav_myAccountData"]</a>

                        </div>

                        @*<ul class="list-group list-group-flush">
                                <li class="list-group-item d-flex justify-content-between align-items-center flex-wrap">
                                    喵
                                </li>
                            </ul>*@
                    </div>
                </div>

                @*正文*@
                <div class="col-md-8">
                    @RenderBody()
                </div>
            </div>

        </div>
    </div>


    @*Footer*@
    <partial name="Footer" />

    <script src="~/js/chino.js" asp-append-version="true"></script>

    <environment include="Development">
        @*开发模式下的JS引用之类的*@
        <script src="~/lib/jquery/dist/jquery.js"></script>
        <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.js"></script>
        <script src="~/lib/vue/vue.js"></script>
    </environment>
    <environment exclude="Development">
        @*发布模式下的js引用之类的*@
        <script src="~/lib/jquery/dist/jquery.min.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-alpha3/dist/js/bootstrap.bundle.min.js"
                asp-fallback-src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"
                asp-fallback-test="bootstrap"
                integrity="sha384-popRpmFF9JQgExhfw5tZT4I9/CI5e2QcuUZPOVXb1m7qUmeR2b50u+YFEYe1wgzy"
                crossorigin="anonymous"></script>

        <script src="https://cdn.jsdelivr.net/npm/vue@2.6.12"
                asp-fallback-src="~/lib/vue/vue.min.js"
                asp-fallback-test="Vue"
                crossorigin="anonymous"></script>
    </environment>

    @await RenderSectionAsync("Scripts", required: false)
</body>
</html>
